package com.hualan.controller;

import com.hualan.pojo.InformBulletin;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.service.InformBulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bulletin")
public class InformBulletinController {

    @Autowired
    private InformBulletinService informBulletinService;

    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result getPageList(@PathVariable int pageNum, @PathVariable int pageSize) {
        PageResult<InformBulletin> pageResult = informBulletinService.getPageList(pageNum, pageSize);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        InformBulletin informBulletin = informBulletinService.getById(id);
        return Result.success(informBulletin);
    }

    @PostMapping
    public Result add(@RequestBody InformBulletin informBulletin) {
        int result = informBulletinService.add(informBulletin);
        return Result.success(result);
    }

    @PutMapping
    public Result update(@RequestBody InformBulletin informBulletin) {
        int result = informBulletinService.update(informBulletin);
        return Result.success(result);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        int result = informBulletinService.delete(id);
        return Result.success(result);
    }

    @GetMapping("/page/{pageNum}/{pageSize}/keyword/{keyword}")
    public Result getPageListByKeyword(@PathVariable int pageNum, @PathVariable int pageSize, @PathVariable String keyword) {
        PageResult<InformBulletin> pageResult = informBulletinService.getPageListByKeyword(pageNum, pageSize, keyword);
        return Result.success(pageResult);
    }
}